package com.example.admin.service.impl;

import com.example.admin.mapper.SchedulerXMapper;
import com.example.admin.model.TaskDisp;
import com.example.admin.result.ResponseResult;
import com.example.admin.scheduler.SchedulerX2;
import com.example.admin.service.SchedulerXService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SchedulerXServiceImpl implements SchedulerXService {

    @Autowired
    SchedulerXMapper schedulerXMapper;

    @Autowired
    SchedulerX2 schedulerX2;

    @Override
    public ResponseResult<String> startSchedulerX(TaskDisp taskDisp) {
        schedulerX2.startSchedulerX2(taskDisp.getTaskDispID());
        return ResponseResult.succeed("00000", "操作成功");
    }

    @Override
    public ResponseResult<String> stopSchedulerX(TaskDisp taskDisp) {
        schedulerX2.stopSchedulerX2(taskDisp.getTaskDispID());
        return ResponseResult.succeed("00000", "操作成功");
    }

    @Override
    public ResponseResult<String> updateSchedulerX(TaskDisp taskDisp) {
        schedulerXMapper.updateTaskDisp(taskDisp);
        schedulerX2.stopSchedulerX2(taskDisp.getTaskDispID());
        return ResponseResult.succeed("00000", "操作成功");
    }

    @Override
    public ResponseResult<String> saveSchedulerX(TaskDisp taskDisp) {
        schedulerXMapper.saveTaskDisp(taskDisp);
        return ResponseResult.succeed("00000", "操作成功");
    }

    @Override
    public ResponseResult<String> deleteSchedulerX(TaskDisp taskDisp) {
        schedulerX2.stopSchedulerX2(taskDisp.getTaskDispID());
        schedulerXMapper.deleteTaskDisp(taskDisp);
        return ResponseResult.succeed("00000", "操作成功");
    }
}
